<!--
 * @Description: 系统右侧菜单工具栏
 * @Author: chaizhou
 * @Date: 2023-02-22 13:47:04
 * @LastEditTime: 2023-02-28 14:28:28
-->
<template>
  <div class="dropDownWrap">
    <div class="toolWrap">
      <button @click="clickFn">主应用修改用户名称</button>
      <span class="hoverText mr4">{{ user.name }} -- {{ user.age }}岁</span>
    </div>
    <div class="toolWrap">
      <el-icon>
        <HelpFilled />
      </el-icon>
    </div>
    <div class="toolWrap">
      <el-icon>
        <Bell />
      </el-icon>
    </div>
    <el-dropdown class="cursor" trigger="click">
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="logOut">退出登录</el-dropdown-item>
          <el-dropdown-item>更改密码</el-dropdown-item>
        </el-dropdown-menu>
      </template>
      <span>
        <span class="hoverText mr4">你好，{{ user.name }}</span>
        <el-icon>
          <CaretBottom />
        </el-icon>
      </span>
    </el-dropdown>
  </div>
</template>

<script setup>
import { onMounted, reactive } from "vue";
import { useRouter } from "vue-router";
import { HelpFilled, Bell, CaretBottom } from "@element-plus/icons-vue";
import store from "store";
import actions from "../../qiankun/actions";

import { storeToRefs } from "pinia";
import { useSharedStore } from "@/stores/useSharedStore";
const userStore = useSharedStore();
const { user } = storeToRefs(userStore);

const useInfo = reactive(actions.getStateCustom());
const router = useRouter();
const logOut = () => {
  store.clearAll();
  router.push("/login");
};

const clickFn = () => {
  const newState = { ...useInfo };
  newState.user = { name: "高启强", age: 60 };
  actions.setGlobalState(newState);
};
onMounted(() => {
  clickFn();
});
</script>

<style lang="less" scoped>
.dropDownWrap {
  display: flex;
  align-items: center;
  .toolWrap {
    cursor: pointer;
    margin-right: 16px;
    padding-right: 16px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    &:after {
      content: "";
      display: inline-block;
      width: 1px;
      height: 14px;
      background-color: #e5e5e5;
      position: absolute;
      top: 50%;
      right: 0;
      transform: translateY(-50%);
    }
  }
}
</style>
